﻿using System;
/*编写面向对象程序实现长方形、正方形、三角形等
形状的类。
1.每个形状类都能计算面积、判断形状是否合法。
请尝试合理使用接口 / 抽象类、属性来实现。
2.随机创建10个形状对象，计算这些对象的面积之和。
*/
namespace exercise2
{
	class exercise03
	{
		static void Main(String[] args)
		{
			Rectangle1 rectangle11 = new Rectangle1(10.0, 5.0);
			Rectangle1 rectanglel2 = new Rectangle1(5.0, 5.0);
			Rectangle1 rectanglel3 = new Rectangle1(5.0, 8.0);
			square1 square1 = new square1(5.0);
			square1 square2 = new square1(9.0);
			square1 square3 = new square1(6.0);
			square1 square4 = new square1(7.0);
			triangle triangle1 = new triangle(5.0, 6.0);
			triangle triangle2 = new triangle(1.0, 6.0);
			triangle triangle3 = new triangle(9.0, 6.0);
		}


	}
	interface IShape
	{
		void Area(double h, double l);
		void check();
	}
	class Rectangle1 : IShape
	{
		private double length;
		private double width;
		private double square;

		public Rectangle1(double length, double width)
		{
			this.length = length;
			this.width = width;
			Area(length, width);
			check();
		}

		public void Area(double h, double l)
		{
			Console.WriteLine(h * l);
			return;
		}

		public void check()
		{
			if (this.length == this.width || this.length <= 0 || this.width <= 0) { Console.WriteLine("长方形不合法"); }
			else
			{
				Console.WriteLine("长方形合法");
			};
		}
	}
	class square1 : IShape
	{
		private double length;
		private double square;

		public square1(double length)
		{
			this.length = length;
			Area(length, length);
			check();

		}

		public void Area(double l, double l2)
		{
			Console.WriteLine(l * l2);
			return;
		}

		public void check()
		{
			if (this.length <= 0) { Console.WriteLine("正方形不合法"); }
			else
			{
				Console.WriteLine("正方形合法");
			};
		}
	}
	class triangle : IShape
	{
		private double height;
		private double length;
		private double square;

		public triangle(double height, double length)
		{
			this.height = height;
			this.length = length;
			Area(height, length);
			check();
		}

		public void Area(double h, double l)
		{
			this.square = h * l * 0.5;
			Console.WriteLine(square);
			return;
		}

		public void check()
		{
			if (this.length <= 0) { Console.WriteLine("三角形不合法"); }
			else
			{
				Console.WriteLine("三角形合法");
			};
		}
	}

}
